#include "Patches.h"

//#define CHEATHOOK 1


unsigned char __fwrite[] =
{
    0x7C, 0x08, 0x02, 0xA6, 
    0x90, 0x01, 0x00, 0x04, 
    0x94, 0x21, 0xFF, 0x88, 
    0x40, 0x86, 0x00, 0x24, 
} ;

unsigned char __fwriteGC[] =
{
    0x94, 0x21, 0xFF, 0xD0,
	0x7C, 0x08, 0x02, 0xA6,
	0x90, 0x01, 0x00, 0x34,
	0xBF, 0x21, 0x00, 0x14, 
    0x7C, 0x99, 0x23, 0x78,
	0x7C, 0xDA, 0x33, 0x78,
	0x7C, 0x7B, 0x1B, 0x78,
	0x7C, 0xBC, 0x2B, 0x78, 
    0x38, 0x80, 0x00, 0x00,
	0x7F, 0x43, 0xD3, 0x78,
} ;
unsigned char __fwriteGCB[] =
{
    0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x04, 0x94, 0x21, 0xFF, 0xB8, 0xBF, 0x21, 0x00, 0x2C, 
    0x3B, 0x44, 0x00, 0x00, 0x3B, 0x66, 0x00, 0x00, 0x3B, 0x83, 0x00, 0x00, 0x3B, 0x25, 0x00, 0x00, 
    0x38, 0x7B, 0x00, 0x00, 0x38, 0x80, 0x00, 0x00, 
} ;

unsigned char patch_fwrite_GC[144] =
{
    0x7C, 0x85, 0x21, 0xD7, 0x40, 0x81, 0x00, 0x84, 0x3C, 0xE0, 0xCC, 0x00, 0x3D, 0x40, 0xCC, 0x00, 
    0x3D, 0x60, 0xCC, 0x00, 0x60, 0xE7, 0x68, 0x14, 0x61, 0x4A, 0x68, 0x24, 0x61, 0x6B, 0x68, 0x20, 
    0x38, 0xC0, 0x00, 0x00, 0x7C, 0x06, 0x18, 0xAE, 0x54, 0x00, 0xA0, 0x16, 0x64, 0x08, 0xB0, 0x00, 
    0x38, 0x00, 0x00, 0xD0, 0x90, 0x07, 0x00, 0x00, 0x7C, 0x00, 0x06, 0xAC, 0x91, 0x0A, 0x00, 0x00, 
    0x7C, 0x00, 0x06, 0xAC, 0x38, 0x00, 0x00, 0x19, 0x90, 0x0B, 0x00, 0x00, 0x7C, 0x00, 0x06, 0xAC, 
    0x80, 0x0B, 0x00, 0x00, 0x7C, 0x00, 0x04, 0xAC, 0x70, 0x09, 0x00, 0x01, 0x40, 0x82, 0xFF, 0xF4, 
    0x80, 0x0A, 0x00, 0x00, 0x7C, 0x00, 0x04, 0xAC, 0x39, 0x20, 0x00, 0x00, 0x91, 0x27, 0x00, 0x00, 
    0x7C, 0x00, 0x06, 0xAC, 0x74, 0x09, 0x04, 0x00, 0x41, 0x82, 0xFF, 0xB8, 0x38, 0xC6, 0x00, 0x01, 
    0x7F, 0x86, 0x20, 0x00, 0x40, 0x9E, 0xFF, 0xA0, 0x7C, 0xA3, 0x2B, 0x78, 0x4E, 0x80, 0x00, 0x20, 
};

unsigned char OSReportDM[] =
{
	0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x04, 0x90, 0xE1, 0x00, 0x08, 0x3C, 0xE0, 0xC0, 0x00, 
	0x90, 0x67, 0x18, 0x60, 0x90, 0x87, 0x18, 0x64, 0x90, 0xA7, 0x18, 0x68, 0x90, 0xC7, 0x18, 0x6C, 
	0x90, 0xE7, 0x18, 0x70, 0x91, 0x07, 0x18, 0x74, 0x80, 0x07, 0x18, 0x60, 0x7C, 0x00, 0x18, 0x00, 
	0x41, 0x82, 0xFF, 0xF8, 0x80, 0xE1, 0x00, 0x08, 0x80, 0x01, 0x00, 0x04, 0x7C, 0x08, 0x03, 0xA6, 
	0x4E, 0x80, 0x00, 0x20, 
} ;

unsigned char DVDLowReadDiscID[156] =
{
    0x94, 0x21, 0xFF, 0xF0, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x14, 0x39, 0x00, 0x00, 0x00, 
    0x3C, 0xE0, 0xA8, 0x00, 0x38, 0xA0, 0x00, 0x20, 0x90, 0x8D, 0x82, 0x30, 0x91, 0x0D, 0x82, 0x08, 
    0x3C, 0xC0, 0xCC, 0x00, 0x3C, 0xE0, 0xA8, 0x00, 0x90, 0xE6, 0x60, 0x08, 0x91, 0x06, 0x60, 0x0C, 
    0x90, 0x66, 0x60, 0x14, 0x90, 0xA6, 0x60, 0x10, 0x90, 0xA6, 0x60, 0x18, 0x38, 0x00, 0x00, 0x03, 
    0x90, 0x06, 0x60, 0x1C, 0x80, 0x06, 0x60, 0x1C, 0x2C, 0x00, 0x00, 0x03, 0x41, 0x82, 0xFF, 0xF8, 
    0x38, 0x00, 0x00, 0x03, 0x3C, 0xC0, 0xC0, 0x00, 0x90, 0xE6, 0x2F, 0x08, 0x91, 0x06, 0x2F, 0x0C, 
    0x90, 0x66, 0x2F, 0x14, 0x90, 0xA6, 0x2F, 0x10, 0x90, 0xA6, 0x2F, 0x18, 0x90, 0x06, 0x2F, 0x1C, 
    0x80, 0x06, 0x2F, 0x1C, 0x2C, 0x00, 0x00, 0x03, 0x41, 0x82, 0xFF, 0xF8, 0x80, 0x06, 0x2F, 0x30, 
    0x70, 0x00, 0x00, 0x14, 0x2C, 0x00, 0x00, 0x00, 0x41, 0x82, 0xFF, 0xF4, 0x80, 0x01, 0x00, 0x14, 
    0x7C, 0x08, 0x03, 0xA6, 0x38, 0x21, 0x00, 0x10, 0x4E, 0x80, 0x00, 0x20, 
} ;

unsigned char DVDLowRead[184] =
{
    0x94, 0x21, 0xFF, 0xF0,
	0x7C, 0x08, 0x02, 0xA6,
	0x90, 0x01, 0x00, 0x14,
	0x93, 0xC1, 0x00, 0x08, 
    0x93, 0xE1, 0x00, 0x0C,
	0x38, 0x00, 0x00, 0x00,
	0x90, 0xCD, 0x82, 0x30,
	0x90, 0x0D, 0x82, 0x08, 

    0x3C, 0xE0, 0xC0, 0x00,
	0x3C, 0x00, 0xA8, 0x00,
	0x90, 0x07, 0x2F, 0x08,
	0x90, 0xA7, 0x2F, 0x0C, 
    0x90, 0x67, 0x2F, 0x14, 
	0x90, 0x87, 0x2F, 0x10,
	0x90, 0x87, 0x2F, 0x18, 
	0x38, 0x00, 0x00, 0x03, 
    0x90, 0x07, 0x2F, 0x1C,
	0x80, 0x07, 0x2F, 0x1C, 
	0x2C, 0x00, 0x00, 0x03,
	0x41, 0x82, 0xFF, 0xF8, 
    0x80, 0x07, 0x2F, 0x30, 
	0x70, 0x00, 0x00, 0x14,
	0x2C, 0x00, 0x00, 0x00, 
	0x41, 0x82, 0xFF, 0xF4, 

    0x3C, 0xC0, 0xCC, 0x00,
	0x3C, 0xE0, 0xAB, 0x00,
	0x90, 0xE6, 0x60, 0x08, 
	0x38, 0x00, 0x00, 0x20, 
    0x90, 0x06, 0x60, 0x0C,
	0x90, 0x66, 0x60, 0x14,
	0x90, 0x06, 0x60, 0x10,
	0x38, 0x00, 0x00, 0x00, 
    0x90, 0x06, 0x60, 0x18,
	0x38, 0x00, 0x00, 0x01, 
	0x90, 0x06, 0x60, 0x1C,
	0x80, 0x06, 0x60, 0x00, 
    0x70, 0x00, 0x00, 0x14,
	0x2C, 0x00, 0x00, 0x00,
	0x41, 0x82, 0xFF, 0xF4,
	0x38, 0x60, 0x00, 0x01, 
    0x83, 0xE1, 0x00, 0x0C,
	0x83, 0xC1, 0x00, 0x08, 
	0x80, 0x01, 0x00, 0x14, 
	0x7C, 0x08, 0x03, 0xA6, 
    0x38, 0x21, 0x00, 0x10, 
	0x4E, 0x80, 0x00, 0x20, 
} ;

unsigned char DVDLowReadShift[184] =
{
    0x94, 0x21, 0xFF, 0xF0,
	0x7C, 0x08, 0x02, 0xA6,
	0x90, 0x01, 0x00, 0x14,
	0x93, 0xC1, 0x00, 0x08, 
    0x93, 0xE1, 0x00, 0x0C,
	0x38, 0x00, 0x00, 0x00,

	0x90, 0xCD, 0x82, 0x30, 
	0x90, 0x0D, 0x82, 0x08, 


    0x3C, 0xE0, 0xC0, 0x00, 
	0x3C, 0x00, 0xA8, 0x00,
	0x90, 0x07, 0x2F, 0x08, 
	0x54, 0xA0, 0xF0, 0xBE, 
    0x90, 0x07, 0x2F, 0x0C, 
	0x90, 0x67, 0x2F, 0x14,
	0x90, 0x87, 0x2F, 0x10, 
	0x90, 0x87, 0x2F, 0x18, 
    0x38, 0x00, 0x00, 0x03, 
	0x90, 0x07, 0x2F, 0x1C, 

	0x80, 0x07, 0x2F, 0x1C, 
	0x2C, 0x00, 0x00, 0x03, 
    0x41, 0x82, 0xFF, 0xF8, 

	0x80, 0x07, 0x2F, 0x30, 
	0x70, 0x00, 0x00, 0x14,
	0x2C, 0x00, 0x00, 0x00, 
    0x41, 0x82, 0xFF, 0xF4, 


	0x3C, 0xC0, 0xCC, 0x00,	
	0x3C, 0xE0, 0xAB, 0x00,	
	0x90, 0xE6, 0x60, 0x08, 
    0x7C, 0x63, 0x22, 0x14,	
	0x90, 0x66, 0x60, 0x14,
	0x90, 0x86, 0x60, 0x10,	
	0x38, 0x00, 0x00, 0x00, 
    0x90, 0x06, 0x60, 0x18,	
	0x38, 0x00, 0x00, 0x01,	
	0x90, 0x06, 0x60, 0x1C,
	0x80, 0x06, 0x60, 0x00, 
    0x70, 0x00, 0x00, 0x14,	
	0x2C, 0x00, 0x00, 0x00,	
	0x41, 0x82, 0xFF, 0xF4,

	0x38, 0x60, 0x00, 0x01,
    0x83, 0xE1, 0x00, 0x0C,
	0x83, 0xC1, 0x00, 0x08,
	0x80, 0x01, 0x00, 0x14,
	0x7C, 0x08, 0x03, 0xA6, 
    0x38, 0x21, 0x00, 0x10,
	0x4E, 0x80, 0x00, 0x20,
} ;


unsigned char DVDIRQWait[32] =
{
    0x57, 0xE0, 0x06, 0xF7,
	0x63, 0xDE, 0x00, 0x01,

	0x3C, 0xA0, 0xC0, 0x00,
	0x80, 0x05, 0x2F, 0x30,
    0x70, 0x00, 0x00, 0x14,
	0x2C, 0x00, 0x00, 0x00,
	0x41, 0x82, 0xFF, 0xF4,
	0x60, 0x00, 0x00, 0x00, 
} ;



unsigned char DVDIRQWaitB[32] =
{
    0x3C, 0xA0, 0xC0, 0x00, 
	0x88, 0x05, 0x2F, 0x38,
	0x2C, 0x00, 0x00, 0xA8, 
	0x40, 0x82, 0x00, 0x14, 
    0x80, 0x05, 0x2F, 0x30, 
	0x70, 0x00, 0x00, 0x14,
	0x2C, 0x00, 0x00, 0x00, 
	0x41, 0x82, 0xFF, 0xF4, 
} ;


unsigned char DVDLowSeek[140] =
{
    0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x04, 0x38, 0x00, 0x00, 0x01, 0x90, 0x03, 0x00, 0x08, 
    0x90, 0x83, 0x00, 0x18, 0x90, 0xC3, 0x00, 0x10, 0x38, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x20, 
    0x90, 0xA3, 0x00, 0x14, 0x90, 0xE3, 0x00, 0x28, 0x3D, 0x00, 0xC0, 0x00, 0x3C, 0x00, 0xA8, 0x00, 
    0x90, 0x08, 0x2F, 0x08, 0x90, 0xC8, 0x2F, 0x0C, 0x90, 0x88, 0x2F, 0x14, 0x90, 0xA8, 0x2F, 0x10, 
    0x90, 0xA8, 0x2F, 0x18, 0x38, 0x00, 0x00, 0x03, 0x90, 0x08, 0x2F, 0x1C, 0x80, 0x08, 0x2F, 0x1C, 
    0x2C, 0x00, 0x00, 0x03, 0x41, 0x82, 0xFF, 0xF8, 0x80, 0x08, 0x2F, 0x30, 0x70, 0x00, 0x00, 0x14, 
    0x2C, 0x00, 0x00, 0x00, 0x41, 0x82, 0xFF, 0xF4, 0x38, 0x00, 0x00, 0x02, 0x90, 0x03, 0x00, 0x0C, 
    0x7C, 0x64, 0x1B, 0x78, 0x7C, 0x63, 0x1B, 0x78, 0x7C, 0xE9, 0x03, 0xA6, 0x4E, 0x80, 0x04, 0x21, 
    0x80, 0x01, 0x00, 0x04, 0x7C, 0x08, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20, 
} ;


unsigned char DVDReadPattern[20] =
{
    0x90, 0x83, 0x00, 0x18,	0x90, 0xA3, 0x00, 0x14,	0x90, 0xC3, 0x00, 0x10,	0x90, 0x03, 0x00, 0x20, 
    0x90, 0xE3, 0x00, 0x28, 
} ;
unsigned char AIResetStreamSampleCount[44] =
{
    0x3C, 0x60, 0xCC, 0x00,	0x80, 0x03, 0x6C, 0x00,	0x54, 0x00, 0x00, 0x3C,	0x7C, 0x00, 0xEB, 0x78, 
    0x90, 0x03, 0x6C, 0x00, 0x80, 0x01, 0x00, 0x24,	0x83, 0xE1, 0x00, 0x1C,	0x83, 0xC1, 0x00, 0x18, 
    0x83, 0xA1, 0x00, 0x14,	0x38, 0x21, 0x00, 0x20,	0x7C, 0x08, 0x03, 0xA6, 
} ;
unsigned char AIResetStreamSampleCountB[] =
{
	0x3C, 0x60, 0xCC, 0x00,	0x80, 0x03, 0x6C, 0x00,	0x54, 0x00, 0x00, 0x3C,	0x7C, 0x00, 0xEB, 0x78,
	0x90, 0x03, 0x6C, 0x00,
} ;
unsigned char ARAMTransfer[104] =
{
    0x3C, 0xE0, 0xC0, 0x00, 0x93, 0x87, 0x24, 0xA0, 0x90, 0xA7, 0x24, 0xA4, 0x53, 0xA6, 0xF8, 0x00, 
    0x90, 0xC7, 0x24, 0xA8,	0x80, 0xA7, 0x24, 0xE8,	0x7C, 0x05, 0x30, 0x40,	0x40, 0x82, 0xFF, 0xF8, 
    0x3D, 0x00, 0xCC, 0x00,	0x38, 0x00, 0x40, 0x00,	0x38, 0x00, 0x40, 0x00,	0xB0, 0x08, 0x50, 0x20, 
    0x38, 0x00, 0x00, 0x20,	0xB0, 0x08, 0x50, 0x22,	0x38, 0x00, 0x00, 0xA0,	0xB0, 0x08, 0x50, 0x24, 
    0x38, 0x00, 0x00, 0x00,	0xB0, 0x08, 0x50, 0x26,	0x38, 0x00, 0x40, 0x00,	0x38, 0x00, 0x40, 0x00, 
    0xB0, 0x07, 0x50, 0x28,	0x38, 0x00, 0x00, 0x20,	0xB0, 0x08, 0x50, 0x2A,	0x80, 0xA8, 0x50, 0x3A, 
    0x2C, 0x05, 0x00, 0x00,	0x40, 0x82, 0xFF, 0xF8, 
} ;
unsigned char ARStartDMA[8] =
{
    0x3C, 0xC0, 0xCC, 0x00,
	0xA0, 0x06, 0x50, 0x20, 
} ;

#ifdef CHEATHOOK
unsigned char kenobigc[4056] =
{
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x26, 0x88, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x21, 0xFF, 0x58, 0x90, 0x01, 0x00, 0x08, 
    0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0xAC, 0x7C, 0x00, 0x00, 0x26, 0x90, 0x01, 0x00, 0x0C, 
    0x7C, 0x09, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x10, 0x7C, 0x01, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x14, 
    0xBC, 0x61, 0x00, 0x18, 0x7F, 0x20, 0x00, 0xA6, 0x63, 0x3A, 0x20, 0x00, 0x73, 0x5A, 0xF9, 0xFF, 
    0x7F, 0x40, 0x01, 0x24, 0xD8, 0x41, 0x00, 0x98, 0xD8, 0x61, 0x00, 0xA0, 0x3F, 0xE0, 0x80, 0x00, 
    0x48, 0x00, 0x06, 0xA9, 0x3A, 0xA0, 0x00, 0x00, 0x3A, 0xC0, 0x00, 0x19, 0x3A, 0xE0, 0x00, 0xD0, 
    0x3F, 0x00, 0xCC, 0x00, 0x63, 0xF2, 0x26, 0x88, 0x80, 0x01, 0x00, 0xAC, 0x90, 0x12, 0x00, 0x04, 
    0x48, 0x00, 0x04, 0x85, 0x41, 0x82, 0x05, 0xFC, 0x2C, 0x1D, 0x00, 0x04, 0x40, 0x80, 0x00, 0x10, 
    0x2C, 0x1D, 0x00, 0x01, 0x41, 0x80, 0x05, 0xEC, 0x48, 0x00, 0x03, 0xA8, 0x41, 0x82, 0x05, 0x48, 
    0x2C, 0x1D, 0x00, 0x06, 0x41, 0x82, 0x00, 0x8C, 0x2C, 0x1D, 0x00, 0x07, 0x41, 0x82, 0x03, 0x8C, 
    0x2C, 0x1D, 0x00, 0x08, 0x41, 0x82, 0x05, 0xD8, 0x2C, 0x1D, 0x00, 0x09, 0x41, 0x82, 0x00, 0xA0, 
    0x2C, 0x1D, 0x00, 0x10, 0x41, 0x82, 0x00, 0x98, 0x2C, 0x1D, 0x00, 0x2F, 0x41, 0x82, 0x00, 0x70, 
    0x2C, 0x1D, 0x00, 0x30, 0x41, 0x82, 0x00, 0x78, 0x2C, 0x1D, 0x00, 0x38, 0x41, 0x82, 0x05, 0x80, 
    0x2C, 0x1D, 0x00, 0x40, 0x41, 0x82, 0x03, 0x9C, 0x2C, 0x1D, 0x00, 0x41, 0x41, 0x82, 0x03, 0xB0, 
    0x2C, 0x1D, 0x00, 0x44, 0x41, 0x82, 0x00, 0x68, 0x2C, 0x1D, 0x00, 0x50, 0x41, 0x82, 0x00, 0x20, 
    0x2C, 0x1D, 0x00, 0x60, 0x41, 0x82, 0x00, 0x24, 0x2C, 0x1D, 0x00, 0x89, 0x41, 0x82, 0x00, 0x50, 
    0x2C, 0x1D, 0x00, 0x99, 0x41, 0x82, 0x05, 0x64, 0x48, 0x00, 0x05, 0x68, 0x80, 0x72, 0x00, 0x00, 
    0x48, 0x00, 0x04, 0x81, 0x48, 0x00, 0x05, 0x5C, 0x48, 0x00, 0x05, 0xE1, 0x48, 0x00, 0x05, 0x54, 
    0x38, 0x80, 0x00, 0x01, 0x90, 0x92, 0x00, 0x00, 0x48, 0x00, 0x05, 0x48, 0x48, 0x00, 0x04, 0x61, 
    0x3A, 0x00, 0x00, 0xA0, 0x63, 0xEC, 0x26, 0xAC, 0x48, 0x00, 0x03, 0x6C, 0x38, 0x60, 0x01, 0x20, 
    0x63, 0xEC, 0x26, 0xAC, 0x48, 0x00, 0x04, 0x21, 0x48, 0x00, 0x05, 0x28, 0x2F, 0x1D, 0x00, 0x10, 
    0x2E, 0x9D, 0x00, 0x44, 0x63, 0xE4, 0x1A, 0xA0, 0x3C, 0x60, 0x80, 0x00, 0x60, 0x63, 0x03, 0x00, 
    0x48, 0x00, 0x05, 0x61, 0x38, 0x63, 0x0A, 0x00, 0x48, 0x00, 0x05, 0x59, 0x38, 0x63, 0x06, 0x00, 
    0x48, 0x00, 0x05, 0x51, 0x63, 0xEC, 0x26, 0x9C, 0x92, 0xAC, 0x00, 0x00, 0x92, 0xAC, 0x00, 0x04, 
    0x92, 0xAC, 0x00, 0x08, 0x63, 0xE4, 0x26, 0xAC, 0x81, 0x24, 0x00, 0x18, 0x80, 0x72, 0x00, 0x00, 
    0x2C, 0x03, 0x00, 0x02, 0x40, 0x82, 0x00, 0x0C, 0x41, 0x96, 0x00, 0x0C, 0x48, 0x00, 0x00, 0x20, 
    0x38, 0x60, 0x00, 0x00, 0x90, 0x6C, 0x00, 0x0C, 0x40, 0x82, 0x00, 0x14, 0x40, 0x96, 0x00, 0x10, 
    0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x02, 0x70, 0x55, 0x29, 0x05, 0xA8, 
    0x91, 0x24, 0x00, 0x18, 0x41, 0x96, 0x04, 0xAC, 0x41, 0x9A, 0x00, 0x08, 0x39, 0x8C, 0x00, 0x04, 
    0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x61, 0x40, 0x99, 0x00, 0x10, 0x39, 0x8C, 0x00, 0x04, 
    0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x51, 0x63, 0xE4, 0x26, 0x9C, 0x80, 0x64, 0x00, 0x00, 
    0x80, 0x84, 0x00, 0x04, 0x7C, 0x72, 0xFB, 0xA6, 0x7C, 0x95, 0xFB, 0xA6, 0x48, 0x00, 0x04, 0x74, 
    0x7C, 0x32, 0x43, 0xA6, 0x7C, 0x3A, 0x02, 0xA6, 0x7C, 0x73, 0x43, 0xA6, 0x7C, 0x7B, 0x02, 0xA6, 
    0x54, 0x63, 0x05, 0xA8, 0x90, 0x60, 0x26, 0xC4, 0x54, 0x63, 0x06, 0x20, 0x60, 0x63, 0x20, 0x00, 
    0x54, 0x63, 0x04, 0x5E, 0x7C, 0x7B, 0x03, 0xA6, 0x3C, 0x60, 0x80, 0x00, 0x60, 0x63, 0x1A, 0xE0, 
    0x7C, 0x7A, 0x03, 0xA6, 0x4C, 0x00, 0x01, 0x2C, 0x7C, 0x00, 0x04, 0xAC, 0x4C, 0x00, 0x00, 0x64, 
    0x3C, 0x60, 0x80, 0x00, 0x60, 0x63, 0x26, 0xAC, 0x90, 0x23, 0x00, 0x14, 0x7C, 0x61, 0x1B, 0x78, 
    0x7C, 0x73, 0x42, 0xA6, 0xBC, 0x41, 0x00, 0x24, 0x7C, 0x24, 0x0B, 0x78, 0x7C, 0x32, 0x42, 0xA6, 
    0x90, 0x04, 0x00, 0x1C, 0x90, 0x24, 0x00, 0x20, 0x7C, 0x68, 0x02, 0xA6, 0x90, 0x64, 0x00, 0x9C, 
    0x7C, 0x60, 0x00, 0x26, 0x90, 0x64, 0x00, 0x00, 0x7C, 0x61, 0x02, 0xA6, 0x90, 0x64, 0x00, 0x04, 
    0x7C, 0x69, 0x02, 0xA6, 0x90, 0x64, 0x00, 0x08, 0x7C, 0x72, 0x02, 0xA6, 0x90, 0x64, 0x00, 0x0C, 
    0x7C, 0x73, 0x02, 0xA6, 0x90, 0x64, 0x00, 0x10, 0x39, 0x20, 0x00, 0x00, 0x7D, 0x32, 0xFB, 0xA6, 
    0x7D, 0x35, 0xFB, 0xA6, 0xD0, 0x04, 0x00, 0xA0, 0xD0, 0x24, 0x00, 0xA4, 0xD0, 0x44, 0x00, 0xA8, 
    0xD0, 0x64, 0x00, 0xAC, 0xD0, 0x84, 0x00, 0xB0, 0xD0, 0xA4, 0x00, 0xB4, 0xD0, 0xC4, 0x00, 0xB8, 
    0xD0, 0xE4, 0x00, 0xBC, 0xD1, 0x04, 0x00, 0xC0, 0xD1, 0x24, 0x00, 0xC4, 0xD1, 0x44, 0x00, 0xC8, 
    0xD1, 0x64, 0x00, 0xCC, 0xD1, 0x84, 0x00, 0xD0, 0xD1, 0xA4, 0x00, 0xD4, 0xD1, 0xC4, 0x00, 0xD8, 
    0xD1, 0xE4, 0x00, 0xDC, 0xD2, 0x04, 0x00, 0xE0, 0xD2, 0x24, 0x00, 0xE4, 0xD2, 0x44, 0x00, 0xE8, 
    0xD2, 0x64, 0x00, 0xEC, 0xD2, 0x84, 0x00, 0xF0, 0xD2, 0xA4, 0x00, 0xF4, 0xD2, 0xC4, 0x00, 0xF8, 
    0xD2, 0xE4, 0x00, 0xFC, 0xD3, 0x04, 0x01, 0x00, 0xD3, 0x24, 0x01, 0x04, 0xD3, 0x44, 0x01, 0x08, 
    0xD3, 0x64, 0x01, 0x0C, 0xD3, 0x84, 0x01, 0x10, 0xD3, 0xA4, 0x01, 0x14, 0xD3, 0xC4, 0x01, 0x18, 
    0xD3, 0xE4, 0x01, 0x1C, 0x3F, 0xE0, 0x80, 0x00, 0x63, 0xE5, 0x26, 0x9C, 0x82, 0x05, 0x00, 0x00, 
    0x82, 0x25, 0x00, 0x04, 0x82, 0x65, 0x00, 0x0C, 0x2C, 0x13, 0x00, 0x00, 0x41, 0x82, 0x00, 0x74, 
    0x2C, 0x13, 0x00, 0x02, 0x40, 0x82, 0x00, 0x18, 0x81, 0x24, 0x00, 0x14, 0x39, 0x33, 0x00, 0x03, 
    0x91, 0x25, 0x00, 0x00, 0x91, 0x25, 0x00, 0x0C, 0x48, 0x00, 0x00, 0x6C, 0x7C, 0x10, 0x98, 0x00, 
    0x41, 0x82, 0x00, 0x38, 0x7C, 0x11, 0x98, 0x00, 0x41, 0x82, 0x00, 0x30, 0x7D, 0x30, 0x8A, 0x14, 
    0x91, 0x25, 0x00, 0x0C, 0x82, 0x05, 0x00, 0x08, 0x2C, 0x10, 0x00, 0x00, 0x41, 0x82, 0x00, 0x48, 
    0x80, 0x64, 0x00, 0x10, 0x7C, 0x10, 0x18, 0x00, 0x40, 0x82, 0x00, 0x10, 0x3A, 0x00, 0x00, 0x00, 
    0x92, 0x05, 0x00, 0x08, 0x48, 0x00, 0x00, 0x30, 0x3A, 0x20, 0x00, 0x00, 0x92, 0x25, 0x00, 0x0C, 
    0x81, 0x24, 0x00, 0x18, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, 0x30, 
    0x7E, 0x12, 0xFB, 0xA6, 0x7E, 0x35, 0xFB, 0xA6, 0x39, 0x20, 0x00, 0x01, 0x91, 0x25, 0x00, 0x0C, 
    0x48, 0x00, 0x00, 0x1C, 0x38, 0xA0, 0x00, 0x02, 0x63, 0xE4, 0x26, 0x88, 0x90, 0xA4, 0x00, 0x00, 
    0x38, 0x60, 0x00, 0x11, 0x48, 0x00, 0x01, 0xBD, 0x4B, 0xFF, 0xFC, 0x31, 0x7C, 0x20, 0x00, 0xA6, 
    0x54, 0x21, 0x07, 0xFA, 0x54, 0x21, 0x04, 0x5E, 0x7C, 0x20, 0x01, 0x24, 0x63, 0xE1, 0x26, 0xAC, 
    0x80, 0x61, 0x00, 0x00, 0x7C, 0x6F, 0xF1, 0x20, 0x80, 0x61, 0x00, 0x14, 0x7C, 0x7A, 0x03, 0xA6, 
    0x80, 0x61, 0x00, 0x18, 0x7C, 0x7B, 0x03, 0xA6, 0x80, 0x61, 0x00, 0x9C, 0x7C, 0x68, 0x03, 0xA6, 
    0xB8, 0x41, 0x00, 0x24, 0x80, 0x01, 0x00, 0x1C, 0x80, 0x21, 0x00, 0x20, 0x4C, 0x00, 0x01, 0x2C, 
    0x7C, 0x00, 0x04, 0xAC, 0x4C, 0x00, 0x00, 0x64, 0x92, 0xB2, 0x00, 0x00, 0x48, 0x00, 0x02, 0x50, 
    0x2E, 0x9D, 0x00, 0x02, 0x38, 0x60, 0x00, 0x08, 0x63, 0xEC, 0x26, 0x90, 0x48, 0x00, 0x00, 0xF9, 
    0x80, 0xAC, 0x00, 0x00, 0x80, 0x6C, 0x00, 0x04, 0x98, 0x65, 0x00, 0x00, 0x41, 0x94, 0x00, 0x10, 
    0xB0, 0x65, 0x00, 0x00, 0x41, 0x96, 0x00, 0x08, 0x90, 0x65, 0x00, 0x00, 0x7C, 0x00, 0x28, 0xAC, 
    0x7C, 0x00, 0x04, 0xAC, 0x7C, 0x00, 0x2F, 0xAC, 0x4C, 0x00, 0x01, 0x2C, 0x48, 0x00, 0x02, 0x04, 
    0x48, 0x00, 0x01, 0x1D, 0x38, 0x60, 0x00, 0x04, 0x63, 0xEC, 0x26, 0x90, 0x48, 0x00, 0x00, 0xB9, 
    0x82, 0x0C, 0x00, 0x00, 0x63, 0xEC, 0x27, 0xD0, 0x48, 0x00, 0x00, 0x1C, 0x48, 0x00, 0x01, 0x01, 
    0x38, 0x60, 0x00, 0x08, 0x63, 0xEC, 0x26, 0x90, 0x48, 0x00, 0x00, 0x9D, 0x82, 0x0C, 0x00, 0x04, 
    0x81, 0x8C, 0x00, 0x00, 0x63, 0xFB, 0x26, 0x98, 0x3A, 0x20, 0x0F, 0x80, 0x48, 0x00, 0x02, 0x39, 
    0x41, 0x82, 0x00, 0x20, 0x7E, 0x23, 0x8B, 0x78, 0x48, 0x00, 0x00, 0x7D, 0x48, 0x00, 0x00, 0xD1, 
    0x41, 0x82, 0xFF, 0xFC, 0x7D, 0x8C, 0x72, 0x14, 0x35, 0x6B, 0xFF, 0xFF, 0x41, 0x81, 0xFF, 0xE8, 
    0x80, 0x7B, 0x00, 0x00, 0x2C, 0x03, 0x00, 0x00, 0x41, 0x82, 0x00, 0x08, 0x48, 0x00, 0x00, 0x59, 
    0x7C, 0x00, 0x60, 0xAC, 0x7C, 0x00, 0x04, 0xAC, 0x7C, 0x00, 0x67, 0xAC, 0x4C, 0x00, 0x01, 0x2C, 
    0x48, 0x00, 0x01, 0x80, 0x7F, 0xC8, 0x02, 0xA6, 0x3C, 0x60, 0xA0, 0x00, 0x48, 0x00, 0x00, 0x15, 
    0x76, 0x03, 0x08, 0x00, 0x56, 0x1D, 0x86, 0x3E, 0x7F, 0xC8, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20, 
    0x92, 0xF8, 0x68, 0x14, 0x90, 0x78, 0x68, 0x24, 0x92, 0xD8, 0x68, 0x20, 0x80, 0xB8, 0x68, 0x20, 
    0x70, 0xA5, 0x00, 0x01, 0x40, 0x82, 0xFF, 0xF8, 0x82, 0x18, 0x68, 0x24, 0x90, 0xB8, 0x68, 0x14, 
    0x4E, 0x80, 0x00, 0x20, 0x7D, 0x48, 0x02, 0xA6, 0x7C, 0x69, 0x03, 0xA6, 0x39, 0xC0, 0x00, 0x00, 
    0x48, 0x00, 0x00, 0x79, 0x48, 0x00, 0x00, 0x75, 0x4B, 0xFF, 0xFF, 0xAD, 0x41, 0x82, 0xFF, 0xF4, 
    0x7F, 0xAE, 0x61, 0xAE, 0x39, 0xCE, 0x00, 0x01, 0x42, 0x00, 0xFF, 0xE8, 0x7D, 0x48, 0x03, 0xA6, 
    0x4E, 0x80, 0x00, 0x20, 0x7D, 0x48, 0x02, 0xA6, 0x7C, 0x69, 0x03, 0xA6, 0x39, 0xC0, 0x00, 0x00, 
    0x7C, 0x6C, 0x70, 0xAE, 0x48, 0x00, 0x00, 0x1D, 0x41, 0x82, 0xFF, 0xF8, 0x39, 0xCE, 0x00, 0x01, 
    0x42, 0x00, 0xFF, 0xF0, 0x7D, 0x48, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20, 0x38, 0x60, 0x00, 0xAA, 
    0x7F, 0xC8, 0x02, 0xA6, 0x54, 0x63, 0xA0, 0x16, 0x64, 0x63, 0xB0, 0x00, 0x3A, 0xC0, 0x00, 0x19, 
    0x3A, 0xE0, 0x00, 0xD0, 0x3F, 0x00, 0xCC, 0x00, 0x4B, 0xFF, 0xFF, 0x69, 0x56, 0x03, 0x37, 0xFF, 
    0x7F, 0xC8, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20, 0x7F, 0xC8, 0x02, 0xA6, 0x3C, 0x60, 0xD0, 0x00, 
    0x4B, 0xFF, 0xFF, 0x51, 0x56, 0x03, 0x37, 0xFF, 0x41, 0x82, 0xFF, 0xF4, 0x7F, 0xC8, 0x03, 0xA6, 
    0x4E, 0x80, 0x00, 0x20, 0x4B, 0xFF, 0xFF, 0xB9, 0x38, 0x60, 0x00, 0x08, 0x63, 0xEC, 0x26, 0x90, 
    0x4B, 0xFF, 0xFF, 0x55, 0x80, 0xAC, 0x00, 0x04, 0x81, 0x8C, 0x00, 0x00, 0x63, 0xFB, 0x26, 0x98, 
    0x62, 0xB1, 0xF8, 0x00, 0x7E, 0x0C, 0x28, 0x50, 0x48, 0x00, 0x00, 0xED, 0x41, 0x81, 0x00, 0x10, 
    0x82, 0x3B, 0x00, 0x00, 0x2C, 0x11, 0x00, 0x00, 0x41, 0x82, 0x00, 0x68, 0x7E, 0x23, 0x8B, 0x78, 
    0x4B, 0xFF, 0xFF, 0x55, 0x4B, 0xFF, 0xFF, 0xA5, 0x4B, 0xFF, 0xFF, 0xA1, 0x4B, 0xFF, 0xFE, 0xD9, 
    0x41, 0x82, 0xFF, 0xF4, 0x2C, 0x1D, 0x00, 0xCC, 0x41, 0x82, 0x00, 0x48, 0x2C, 0x1D, 0x00, 0xBB, 
    0x41, 0x82, 0xFF, 0xDC, 0x2C, 0x1D, 0x00, 0xAA, 0x40, 0x82, 0xFF, 0xDC, 0x7D, 0x8C, 0x72, 0x14, 
    0x35, 0x6B, 0xFF, 0xFF, 0x41, 0x80, 0x00, 0x2C, 0x4B, 0xFF, 0xFF, 0xB4, 0x7E, 0xB5, 0xFB, 0xA6, 
    0x7E, 0xB2, 0xFB, 0xA6, 0x63, 0xE4, 0x26, 0xAC, 0x81, 0x24, 0x00, 0x18, 0x55, 0x29, 0x05, 0xA8, 
    0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, 0x0C, 0x38, 0x60, 0x00, 0x80, 0x4B, 0xFF, 0xFF, 0x25, 
    0x80, 0x92, 0x00, 0x00, 0x2C, 0x04, 0x00, 0x00, 0x40, 0x82, 0xF9, 0xF8, 0xC8, 0x41, 0x00, 0x98, 
    0xC8, 0x61, 0x00, 0xA0, 0x7F, 0x20, 0x00, 0xA6, 0x80, 0x01, 0x00, 0xAC, 0x7C, 0x08, 0x03, 0xA6, 
    0x80, 0x01, 0x00, 0x0C, 0x7C, 0x0F, 0xF1, 0x20, 0x80, 0x01, 0x00, 0x10, 0x7C, 0x09, 0x03, 0xA6, 
    0x80, 0x01, 0x00, 0x14, 0x7C, 0x01, 0x03, 0xA6, 0xB8, 0x61, 0x00, 0x18, 0x80, 0x01, 0x00, 0x08, 
    0x38, 0x21, 0x00, 0xA8, 0x4C, 0x00, 0x01, 0x2C, 0x7C, 0x00, 0x04, 0xAC, 0x4E, 0x80, 0x00, 0x20, 
    0x7E, 0x23, 0x20, 0x50, 0x3C, 0xA0, 0x48, 0x00, 0x52, 0x25, 0x01, 0xBA, 0x90, 0xA3, 0x00, 0x00, 
    0x7C, 0x00, 0x18, 0xAC, 0x7C, 0x00, 0x04, 0xAC, 0x7C, 0x00, 0x1F, 0xAC, 0x4C, 0x00, 0x01, 0x2C, 
    0x4E, 0x80, 0x00, 0x20, 0x7D, 0x70, 0x8B, 0xD7, 0x7D, 0x4B, 0x89, 0xD6, 0x7D, 0x4A, 0x80, 0x50, 
    0x91, 0x5B, 0x00, 0x00, 0x4E, 0x80, 0x00, 0x20, 0x7F, 0x88, 0x02, 0xA6, 0x63, 0xEF, 0x27, 0xD0, 
    0x63, 0xE7, 0x18, 0x08, 0x3C, 0xC0, 0x80, 0x00, 0x7C, 0xD4, 0x33, 0x78, 0x39, 0x00, 0x00, 0x00, 
    0x3C, 0x60, 0x00, 0xD0, 0x60, 0x63, 0xC0, 0xDE, 0x80, 0x8F, 0x00, 0x00, 0x7C, 0x03, 0x20, 0x00, 
    0x40, 0x82, 0x00, 0x18, 0x80, 0x8F, 0x00, 0x04, 0x7C, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x0C, 
    0x39, 0xEF, 0x00, 0x08, 0x48, 0x00, 0x00, 0x0C, 0x7F, 0x88, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x20, 
    0x80, 0x6F, 0x00, 0x00, 0x80, 0x8F, 0x00, 0x04, 0x39, 0xEF, 0x00, 0x08, 0x71, 0x09, 0x00, 0x01, 
    0x2F, 0x89, 0x00, 0x00, 0x39, 0x20, 0x00, 0x00, 0x54, 0x6A, 0x1F, 0x7E, 0x54, 0x65, 0x3F, 0x7E, 
    0x74, 0x6B, 0x10, 0x00, 0x54, 0x63, 0x01, 0xFE, 0x40, 0x82, 0x00, 0x0C, 0x54, 0xCC, 0x00, 0x0C, 
    0x48, 0x00, 0x00, 0x08, 0x7E, 0x8C, 0xA3, 0x78, 0x2E, 0x05, 0x00, 0x00, 0x2C, 0x0A, 0x00, 0x01, 
    0x41, 0xA0, 0x00, 0x2C, 0x41, 0xA2, 0x00, 0xE4, 0x2C, 0x0A, 0x00, 0x03, 0x41, 0xA0, 0x01, 0xB0, 
    0x41, 0x82, 0x02, 0x54, 0x2C, 0x0A, 0x00, 0x05, 0x41, 0x80, 0x02, 0xDC, 0x41, 0xA2, 0x04, 0xE8, 
    0x2C, 0x0A, 0x00, 0x07, 0x41, 0xA0, 0x05, 0x14, 0x48, 0x00, 0x05, 0xF8, 0x7D, 0x8C, 0x1A, 0x14, 
    0x2C, 0x05, 0x00, 0x03, 0x41, 0x82, 0x00, 0x48, 0x41, 0x81, 0x00, 0x60, 0x40, 0xBE, 0xFF, 0x84, 
    0x2E, 0x05, 0x00, 0x01, 0x41, 0x91, 0x00, 0x2C, 0x54, 0x8A, 0x84, 0x3E, 0x41, 0x92, 0x00, 0x10, 
    0x7C, 0x89, 0x61, 0xAE, 0x39, 0x29, 0x00, 0x01, 0x48, 0x00, 0x00, 0x0C, 0x7C, 0x89, 0x63, 0x2E, 
    0x39, 0x29, 0x00, 0x02, 0x35, 0x4A, 0xFF, 0xFF, 0x40, 0xA0, 0xFF, 0xE4, 0x4B, 0xFF, 0xFF, 0x54, 
    0x55, 0x8C, 0x00, 0x3A, 0x90, 0x8C, 0x00, 0x00, 0x4B, 0xFF, 0xFF, 0x48, 0x7C, 0x89, 0x23, 0x78, 
    0x40, 0x9E, 0x04, 0xD0, 0x35, 0x29, 0xFF, 0xFF, 0x41, 0x80, 0x04, 0xC8, 0x7C, 0xA9, 0x78, 0xAE, 
    0x7C, 0xA9, 0x61, 0xAE, 0x4B, 0xFF, 0xFF, 0xF0, 0x39, 0xEF, 0x00, 0x08, 0x40, 0xBE, 0xFF, 0x24, 
    0x80, 0xAF, 0xFF, 0xF8, 0x81, 0x6F, 0xFF, 0xFC, 0x54, 0xB1, 0x04, 0x3E, 0x54, 0xAA, 0x85, 0x3E, 
    0x54, 0xA5, 0x27, 0x3E, 0x2E, 0x85, 0x00, 0x01, 0x41, 0x96, 0x00, 0x10, 0x41, 0xB5, 0x00, 0x14, 
    0x7C, 0x89, 0x61, 0xAE, 0x48, 0x00, 0x00, 0x10, 0x7C, 0x89, 0x63, 0x2E, 0x48, 0x00, 0x00, 0x08, 
    0x7C, 0x89, 0x61, 0x2E, 0x7C, 0x84, 0x5A, 0x14, 0x7D, 0x29, 0x8A, 0x14, 0x35, 0x4A, 0xFF, 0xFF, 
    0x40, 0x80, 0xFF, 0xD4, 0x4B, 0xFF, 0xFE, 0xDC, 0x54, 0x69, 0x07, 0xFF, 0x41, 0x82, 0x00, 0x10, 
    0x55, 0x08, 0xF8, 0x7E, 0x71, 0x09, 0x00, 0x01, 0x2F, 0x89, 0x00, 0x00, 0x2E, 0x85, 0x00, 0x04, 
    0x2D, 0x8A, 0x00, 0x05, 0x7D, 0x13, 0x43, 0x78, 0x52, 0x68, 0x08, 0x3C, 0x40, 0x9E, 0x00, 0x78, 
    0x41, 0x8D, 0x04, 0xBC, 0x7D, 0x8C, 0x1A, 0x14, 0x41, 0x8C, 0x00, 0x0C, 0x41, 0x94, 0x00, 0x30, 
    0x48, 0x00, 0x00, 0x1C, 0x40, 0x94, 0x00, 0x10, 0x55, 0x8C, 0x00, 0x3A, 0x81, 0x6C, 0x00, 0x00, 
    0x48, 0x00, 0x00, 0x1C, 0x55, 0x8C, 0x00, 0x3C, 0xA1, 0x6C, 0x00, 0x00, 0x7C, 0x89, 0x20, 0xF8, 
    0x55, 0x29, 0x84, 0x3E, 0x7D, 0x6B, 0x48, 0x38, 0x54, 0x84, 0x04, 0x3E, 0x7F, 0x0B, 0x20, 0x40, 
    0x70, 0xA9, 0x00, 0x03, 0x41, 0x82, 0x00, 0x18, 0x2C, 0x09, 0x00, 0x02, 0x41, 0x82, 0x00, 0x18, 
    0x41, 0x81, 0x00, 0x1C, 0x40, 0x9A, 0x00, 0x20, 0x48, 0x00, 0x00, 0x18, 0x41, 0x9A, 0x00, 0x18, 
    0x48, 0x00, 0x00, 0x10, 0x41, 0x99, 0x00, 0x10, 0x48, 0x00, 0x00, 0x08, 0x41, 0x98, 0x00, 0x08, 
    0x61, 0x08, 0x00, 0x01, 0x40, 0x8E, 0xFE, 0x3C, 0x41, 0x94, 0xFE, 0x38, 0x81, 0x6F, 0xFF, 0xF8, 
    0x40, 0x9E, 0x00, 0x20, 0x70, 0x6C, 0x00, 0x08, 0x41, 0x82, 0x00, 0x0C, 0x71, 0x0C, 0x00, 0x01, 
    0x41, 0x82, 0x00, 0x10, 0x39, 0x8B, 0x00, 0x10, 0x51, 0x8B, 0x03, 0x36, 0x48, 0x00, 0x00, 0x08, 
    0x55, 0x6B, 0x07, 0x16, 0x91, 0x6F, 0xFF, 0xF8, 0x4B, 0xFF, 0xFE, 0x08, 0x40, 0xBE, 0xFE, 0x04, 
    0x54, 0x69, 0x16, 0xBA, 0x54, 0x6E, 0x87, 0xFE, 0x2D, 0x8E, 0x00, 0x00, 0x2E, 0x05, 0x00, 0x04, 
    0x70, 0xAE, 0x00, 0x03, 0x2E, 0x8E, 0x00, 0x02, 0x41, 0x94, 0x00, 0x14, 0x41, 0x96, 0x00, 0x50, 
    0x7C, 0x64, 0x07, 0x34, 0x7C, 0x84, 0x7A, 0x14, 0x48, 0x00, 0x00, 0x68, 0x54, 0x65, 0xA7, 0xFF, 
    0x41, 0x82, 0x00, 0x0C, 0x7D, 0x27, 0x48, 0x2E, 0x7C, 0x84, 0x4A, 0x14, 0x41, 0x8E, 0x00, 0x08, 
    0x7C, 0x8C, 0x22, 0x14, 0x2E, 0x8E, 0x00, 0x01, 0x41, 0x96, 0x00, 0x08, 0x80, 0x84, 0x00, 0x00, 
    0x54, 0x63, 0x67, 0xFF, 0x41, 0x82, 0x00, 0x3C, 0x40, 0x90, 0x00, 0x0C, 0x7C, 0x84, 0x32, 0x14, 
    0x48, 0x00, 0x00, 0x30, 0x7C, 0x84, 0x82, 0x14, 0x48, 0x00, 0x00, 0x28, 0x54, 0x65, 0xA7, 0xFF, 
    0x41, 0x82, 0x00, 0x0C, 0x7D, 0x27, 0x48, 0x2E, 0x7C, 0x84, 0x4A, 0x14, 0x40, 0x90, 0x00, 0x0C, 
    0x7C, 0xCC, 0x21, 0x2E, 0x4B, 0xFF, 0xFD, 0x7C, 0x7E, 0x0C, 0x21, 0x2E, 0x4B, 0xFF, 0xFD, 0x74, 
    0x40, 0x90, 0x00, 0x0C, 0x7C, 0x86, 0x23, 0x78, 0x4B, 0xFF, 0xFD, 0x68, 0x7C, 0x90, 0x23, 0x78, 
    0x4B, 0xFF, 0xFD, 0x60, 0x54, 0x89, 0x1E, 0x78, 0x39, 0x29, 0x00, 0x40, 0x2C, 0x05, 0x00, 0x02, 
    0x41, 0x80, 0x00, 0x4C, 0x54, 0x6B, 0x67, 0xBF, 0x2C, 0x0B, 0x00, 0x01, 0x41, 0x80, 0x00, 0x14, 
    0x41, 0x82, 0x00, 0x08, 0x48, 0x00, 0x00, 0x10, 0x41, 0xBE, 0xFD, 0x38, 0x48, 0x00, 0x00, 0x08, 
    0x40, 0xBE, 0xFD, 0x30, 0x2C, 0x05, 0x00, 0x03, 0x41, 0x81, 0x00, 0x10, 0x41, 0xA2, 0x00, 0x10, 
    0x7D, 0xE7, 0x48, 0x2E, 0x4B, 0xFF, 0xFD, 0x1C, 0x7D, 0xE7, 0x49, 0x2E, 0x7C, 0x64, 0x07, 0x34, 
    0x54, 0x84, 0x1A, 0x78, 0x7D, 0xEF, 0x22, 0x14, 0x4B, 0xFF, 0xFD, 0x08, 0x40, 0xBE, 0xFD, 0x04, 
    0x7C, 0xA7, 0x4A, 0x14, 0x40, 0x92, 0x00, 0x14, 0x54, 0x64, 0x04, 0x3E, 0x91, 0xE5, 0x00, 0x00, 
    0x90, 0x85, 0x00, 0x04, 0x4B, 0xFF, 0xFC, 0xEC, 0x81, 0x25, 0x00, 0x04, 0x2C, 0x09, 0x00, 0x00, 
    0x41, 0xA2, 0xFC, 0xE0, 0x39, 0x29, 0xFF, 0xFF, 0x91, 0x25, 0x00, 0x04, 0x81, 0xE5, 0x00, 0x00, 
    0x4B, 0xFF, 0xFC, 0xD0, 0x40, 0xBE, 0xFC, 0xCC, 0x54, 0x6B, 0x16, 0xBA, 0x7E, 0x47, 0x5A, 0x14, 
    0x81, 0x32, 0x00, 0x00, 0x54, 0x6E, 0x67, 0xBE, 0x41, 0x92, 0x00, 0x84, 0x2E, 0x05, 0x00, 0x05, 
    0x40, 0x90, 0x01, 0x74, 0x2E, 0x05, 0x00, 0x03, 0x40, 0x90, 0x00, 0x90, 0x2E, 0x05, 0x00, 0x01, 
    0x54, 0x65, 0x87, 0xFF, 0x41, 0x82, 0x00, 0x08, 0x7C, 0x8C, 0x22, 0x14, 0x2F, 0x0E, 0x00, 0x01, 
    0x40, 0x92, 0x00, 0x24, 0x41, 0xB9, 0x00, 0x18, 0x41, 0x9A, 0x00, 0x0C, 0x88, 0x84, 0x00, 0x00, 
    0x48, 0x00, 0x00, 0xF8, 0xA0, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xF0, 0x80, 0x84, 0x00, 0x00, 
    0x48, 0x00, 0x00, 0xE8, 0x54, 0x73, 0xE5, 0x3E, 0x41, 0xB9, 0x00, 0x20, 0x41, 0x9A, 0x00, 0x10, 
    0x99, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x01, 0x48, 0x00, 0x00, 0x18, 0xB1, 0x24, 0x00, 0x00, 
    0x38, 0x84, 0x00, 0x02, 0x48, 0x00, 0x00, 0x0C, 0x91, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x04, 
    0x36, 0x73, 0xFF, 0xFF, 0x40, 0x80, 0xFF, 0xD4, 0x4B, 0xFF, 0xFC, 0x38, 0x54, 0x65, 0x87, 0xFF, 
    0x41, 0x82, 0x00, 0x08, 0x7C, 0x84, 0x62, 0x14, 0x71, 0xC5, 0x00, 0x01, 0x41, 0x82, 0x00, 0x9C, 
    0x7C, 0x84, 0x4A, 0x14, 0x48, 0x00, 0x00, 0x94, 0x54, 0x6A, 0x87, 0xBE, 0x54, 0x8E, 0x16, 0xBA, 
    0x7E, 0x67, 0x72, 0x14, 0x40, 0x92, 0x00, 0x08, 0x3A, 0x6F, 0xFF, 0xFC, 0x80, 0x92, 0x00, 0x00, 
    0x81, 0x33, 0x00, 0x00, 0x71, 0x4B, 0x00, 0x01, 0x41, 0x82, 0x00, 0x08, 0x7C, 0x92, 0x23, 0x78, 
    0x71, 0x4B, 0x00, 0x02, 0x41, 0x82, 0x00, 0x10, 0x7D, 0x33, 0x4B, 0x78, 0x40, 0xB2, 0x00, 0x08, 
    0x7E, 0x6C, 0x9A, 0x14, 0x54, 0x65, 0x67, 0x3F, 0x2C, 0x05, 0x00, 0x09, 0x40, 0x80, 0x00, 0x54, 
    0x48, 0x00, 0x00, 0x79, 0x7C, 0x89, 0x22, 0x14, 0x48, 0x00, 0x00, 0x40, 0x7C, 0x89, 0x21, 0xD6, 
    0x48, 0x00, 0x00, 0x38, 0x7D, 0x24, 0x23, 0x78, 0x48, 0x00, 0x00, 0x30, 0x7D, 0x24, 0x20, 0x38, 
    0x48, 0x00, 0x00, 0x28, 0x7D, 0x24, 0x22, 0x78, 0x48, 0x00, 0x00, 0x20, 0x7D, 0x24, 0x20, 0x30, 
    0x48, 0x00, 0x00, 0x18, 0x7D, 0x24, 0x24, 0x30, 0x48, 0x00, 0x00, 0x10, 0x5D, 0x24, 0x20, 0x3E, 
    0x48, 0x00, 0x00, 0x08, 0x7D, 0x24, 0x26, 0x30, 0x90, 0x92, 0x00, 0x00, 0x4B, 0xFF, 0xFB, 0x84, 
    0x2C, 0x05, 0x00, 0x0A, 0x41, 0x81, 0xFB, 0x7C, 0xC0, 0x52, 0x00, 0x00, 0xC0, 0x73, 0x00, 0x00, 
    0x41, 0x82, 0x00, 0x0C, 0xEC, 0x43, 0x10, 0x2A, 0x48, 0x00, 0x00, 0x08, 0xEC, 0x43, 0x00, 0xB2, 
    0xD0, 0x52, 0x00, 0x00, 0x4B, 0xFF, 0xFB, 0x5C, 0x7D, 0x48, 0x02, 0xA6, 0x54, 0xA5, 0x1E, 0x78, 
    0x7D, 0x4A, 0x2A, 0x14, 0x80, 0x92, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x7D, 0x48, 0x03, 0xA6, 
    0x4E, 0x80, 0x00, 0x20, 0x40, 0xBE, 0xFB, 0x3C, 0x54, 0x69, 0xC0, 0x3E, 0x7D, 0x8E, 0x63, 0x78, 
    0x48, 0x00, 0x00, 0x35, 0x41, 0x92, 0x00, 0x0C, 0x7E, 0x31, 0x22, 0x14, 0x48, 0x00, 0x00, 0x08, 
    0x7D, 0x29, 0x22, 0x14, 0x54, 0x64, 0xC4, 0x3F, 0x38, 0xA0, 0x00, 0x00, 0x41, 0x82, 0xFB, 0x14, 
    0x7D, 0x45, 0x88, 0xAE, 0x7D, 0x45, 0x49, 0xAE, 0x38, 0xA5, 0x00, 0x01, 0x7C, 0x05, 0x20, 0x00, 
    0x4B, 0xFF, 0xFF, 0xEC, 0x2E, 0x8A, 0x00, 0x04, 0x55, 0x31, 0x36, 0xBA, 0x2C, 0x11, 0x00, 0x3C, 
    0x7E, 0x27, 0x88, 0x2E, 0x40, 0x82, 0x00, 0x08, 0x7D, 0xD1, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 
    0xA2, 0x31, 0x00, 0x00, 0x55, 0x29, 0x56, 0xBA, 0x2C, 0x09, 0x00, 0x3C, 0x7D, 0x27, 0x48, 0x2E, 
    0x40, 0x82, 0x00, 0x08, 0x7D, 0xC9, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 0xA1, 0x29, 0x00, 0x00, 
    0x4E, 0x80, 0x00, 0x20, 0x2C, 0x05, 0x00, 0x04, 0x40, 0x80, 0x00, 0x28, 0x7C, 0x89, 0x23, 0x78, 
    0x7D, 0xC3, 0x62, 0x14, 0x55, 0xCE, 0x00, 0x3C, 0x4B, 0xFF, 0xFF, 0xAD, 0x7C, 0x84, 0x20, 0xF8, 
    0x54, 0x84, 0x04, 0x3E, 0x7D, 0x2B, 0x20, 0x38, 0x7E, 0x24, 0x20, 0x38, 0x4B, 0xFF, 0xFB, 0xBC, 
    0x54, 0x6B, 0xE4, 0x3E, 0x4B, 0xFF, 0xFB, 0xB4, 0x7C, 0x92, 0x23, 0x78, 0x54, 0x84, 0x18, 0x38, 
    0x40, 0x92, 0x00, 0x20, 0x40, 0x9E, 0x00, 0x0C, 0x7D, 0xE8, 0x03, 0xA6, 0x4E, 0x80, 0x00, 0x21, 
    0x7D, 0xE4, 0x7A, 0x14, 0x39, 0xEF, 0x00, 0x07, 0x55, 0xEF, 0x00, 0x38, 0x4B, 0xFF, 0xFA, 0x64, 
    0x2E, 0x05, 0x00, 0x03, 0x41, 0x91, 0x00, 0x5C, 0x3C, 0xA0, 0x48, 0x00, 0x7D, 0x83, 0x62, 0x14, 
    0x55, 0x8C, 0x00, 0x3A, 0x40, 0x92, 0x00, 0x20, 0x40, 0xBE, 0xFA, 0x48, 0x56, 0x44, 0x00, 0x3A, 
    0x7C, 0x8C, 0x20, 0x50, 0x50, 0x85, 0x01, 0xBA, 0x50, 0x65, 0x07, 0xFE, 0x90, 0xAC, 0x00, 0x00, 
    0x4B, 0xFF, 0xFA, 0x30, 0x40, 0xBE, 0xFF, 0xBC, 0x7D, 0x2C, 0x78, 0x50, 0x51, 0x25, 0x01, 0xBA, 
    0x90, 0xAC, 0x00, 0x00, 0x39, 0x8C, 0x00, 0x04, 0x7D, 0x6F, 0x22, 0x14, 0x39, 0x6B, 0xFF, 0xFC, 
    0x7D, 0x2B, 0x60, 0x50, 0x51, 0x25, 0x01, 0xBA, 0x90, 0xAB, 0x00, 0x00, 0x4B, 0xFF, 0xFF, 0x94, 
    0x2E, 0x05, 0x00, 0x06, 0x41, 0x92, 0x00, 0x28, 0x4B, 0xFF, 0xFB, 0x20, 0x55, 0x8C, 0x84, 0x3E, 
    0x56, 0x44, 0x84, 0x3E, 0x56, 0x52, 0x04, 0x3E, 0x7C, 0x0C, 0x20, 0x00, 0x41, 0x80, 0xFB, 0xA4, 
    0x7C, 0x0C, 0x90, 0x00, 0x40, 0x80, 0xFB, 0x9C, 0x4B, 0xFF, 0xF9, 0xD8, 0x56, 0x45, 0xFF, 0xFE, 
    0x68, 0xA5, 0x00, 0x01, 0x71, 0x03, 0x00, 0x01, 0x7C, 0x05, 0x18, 0x00, 0x41, 0x82, 0x00, 0x1C, 
    0x51, 0x12, 0x0F, 0xBC, 0x6A, 0x52, 0x00, 0x02, 0x56, 0x45, 0xFF, 0xFF, 0x41, 0x82, 0x00, 0x08, 
    0x6A, 0x52, 0x00, 0x01, 0x92, 0x4F, 0xFF, 0xFC, 0x52, 0x48, 0x07, 0xFE, 0x4B, 0xFF, 0xF9, 0xA4, 
    0x2C, 0x0B, 0x00, 0x00, 0x40, 0x82, 0xF9, 0x94, 0x40, 0x92, 0x00, 0x0C, 0x39, 0x00, 0x00, 0x00, 
    0x48, 0x00, 0x00, 0x14, 0x54, 0x69, 0x06, 0xFF, 0x40, 0x82, 0x00, 0x08, 0x40, 0x9E, 0x00, 0x10, 
    0x54, 0x65, 0x67, 0xFE, 0x7D, 0x08, 0x4C, 0x30, 0x7D, 0x08, 0x2A, 0x78, 0x54, 0x85, 0x00, 0x1F, 
    0x41, 0x82, 0x00, 0x08, 0x7C, 0xA6, 0x2B, 0x78, 0x54, 0x85, 0x80, 0x1F, 0x41, 0x82, 0x00, 0x08, 
    0x7C, 0xB0, 0x2B, 0x78, 0x4B, 0xFF, 0xF9, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
} ;
#endif


unsigned char DVDReadAbsAsyncPrio[144] =
{
    0x94, 0x21, 0xFF, 0xF0, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x14, 0x38, 0x00, 0x00, 0x01, 
    0x90, 0x03, 0x00, 0x08, 0x90, 0x03, 0x00, 0x0C, 0x90, 0xA3, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x00, 
    0x90, 0x03, 0x00, 0x20, 0x7C, 0xE8, 0x03, 0xA6, 0x3C, 0xE0, 0xC0, 0x00, 0x3C, 0x00, 0xA8, 0x00, 
    0x90, 0x07, 0x2F, 0x08, 0x80, 0x03, 0x00, 0x30, 0x54, 0xC0, 0xF0, 0xBE, 0x90, 0x07, 0x2F, 0x0C, 
    0x90, 0x87, 0x2F, 0x14, 0x90, 0xA7, 0x2F, 0x10, 0x90, 0xA7, 0x2F, 0x18, 0x38, 0x00, 0x00, 0x03, 
    0x90, 0x07, 0x2F, 0x1C, 0x80, 0x07, 0x2F, 0x1C, 0x2C, 0x00, 0x00, 0x03, 0x41, 0x82, 0xFF, 0xF8, 
    0x80, 0x07, 0x2F, 0x30, 0x70, 0x00, 0x00, 0x14, 0x2C, 0x00, 0x00, 0x00, 0x41, 0x82, 0xFF, 0xF4, 
    0x7C, 0x64, 0x1B, 0x78, 0x7C, 0xA3, 0x2B, 0x78, 0x4E, 0x80, 0x00, 0x21, 0x38, 0x60, 0x00, 0x01, 
    0x80, 0x01, 0x00, 0x14, 0x7C, 0x08, 0x03, 0xA6, 0x38, 0x21, 0x00, 0x10, 0x4E, 0x80, 0x00, 0x20, 
} ;


void PatchGCIPL( void )
{
	write32( 0x1301310, 0x60000000 );	//DVD Patch fix
	write32( 0x1301404, 0x60000000 );	//DVD Patch fix

	memcpy( (void*)0x01304234, DVDLowReadDiscID, sizeof(DVDLowReadDiscID) );
	memcpy( (void*)0x01304048, DVDLowRead, sizeof(DVDLowRead) );
	memcpy( (void*)0x01303DD0, DVDIRQWait, sizeof(DVDIRQWait) );
	
	//memcpy( (void*)0x1306938, DVDLowReadDiscID, sizeof(DVDLowReadDiscID) );	//DVDReadDisKID
	//memcpy( (void*)0x1306864, DVDLowReadDiscID, sizeof(DVDLowReadDiscID) );	//DVDReadDisCID
	//memcpy( (void*)0x1306794, DVDLowRead, sizeof(DVDLowRead) );				//DVDRead
		
	//memcpy( (void*)0x1301DA0, OSReportDM, sizeof(OSReportDM) );		//BS2Report
	//memcpy( (void*)0x1301CEC, OSReportDM, sizeof(OSReportDM) );		//OSReport

//	memcpy( (void*)0x1304320, OSReportDM, sizeof(OSReportDM) );
//
//	write32( 0x1301AE8, 0x60000000 );
//
////OSReport
//u32 newval = (0x1304320 - 0x1301CEC);
//	newval&= 0x03FFFFFC;
//	newval|= 0x48000000;
//	write32( 0x1301CEC, newval );
////BS2Report
//	newval = (0x1304320 - 0x1301DA0);
//	newval&= 0x03FFFFFC;
//	newval|= 0x48000000;
//	write32( 0x1301DA0, newval );
////BS2Panic
//	newval = (0x1304320 - 0x1301D3C);
//	newval&= 0x03FFFFFC;
//	newval|= 0x48000000;
//	write32( 0x1301D3C, newval );
////UNKReport
//	newval = (0x1304320 - 0x13117AC);
//	newval&= 0x03FFFFFC;
//	newval|= 0x48000000;
//	write32( 0x13117AC, newval );
	
	//write32( 0x13017F0, 0x38600001 );
	//write32( 0x13018C0, 0x60000000 );
	//write32( 0x13014BC, 0x60000000 );
	//
	//memcpy( (void*)0x1800, rawData, sizeof(rawData) ); 
	//	
	//write32( P2C(read32(0x1808)), 1 );

	//u32 newval = (0x18A8 - 0x1313524);
	//newval&= 0x03FFFFFC;
	//newval|= 0x48000000;
	//write32( 0x1313524, newval );

}

u32 __DVDInterruptHandler = 0;
u32 AlarmHandlerForTimeout = 0;
void DoPatches( char *ptr, u32 size, u32 SectionOffset )
{
	//dbgprintf("DoPatches( %p, %d, %X)\n", ptr, size, SectionOffset );

	u32 i=0,j=0,offset=0;
	
	u32 Timer = read32(HW_TIMER);

	//for( i=0; i < size; i+=4 )
	//{
	//	if( read32( (u32)ptr + i ) == 0x3C03F2EB && read32( (u32)ptr + i + 4 ) == 0x2800EA5E )
	//	{
	//		//dbgprintf("0xD15EA5E@0x%08X\n", ptr + i + SectionOffset );

	//		//Find load opcode which is always the current address space!
	//		for( j=i; j > 0; j-=4 )
	//		{
	//			if( (read32( (u32)ptr + j ) & 0xFFFF) == ((SectionOffset+j)>>16) ||		// addi case
	//				(read32( (u32)ptr + j ) & 0xFFFF) == (((SectionOffset+j)>>16)+1)	// subi case
	//				)
	//			{
	//				offset = (u32)ptr + j;
	//				//dbgprintf("lis@0x%08X\n", offset + SectionOffset );
	//				break;
	//			}
	//		}

	//		//Find next addi/subi opcode
	//		for( ;j < size; j+=4 )
	//		{
	//			if( (read32( (u32)ptr + j ) & 0xFC000000) == 0x38000000 )
	//			{
	//				//dbgprintf("addi/subi@0x%08X\n", ptr + j + SectionOffset );

	//				__DVDInterruptHandler = read32((u32)ptr + j) & 0xFFFF;
	//				if( __DVDInterruptHandler >> 15 )		// subi
	//				{
	//					__DVDInterruptHandler = (read32(offset) << 16) - (((~read32((u32)ptr + j)) & 0xFFFF) + 1);

	//				} else {			// addi
	//					__DVDInterruptHandler |= read32(offset) << 16;
	//				}
	//				
	//				dbgprintf("__DVDInterruptHandler@0x%08x", __DVDInterruptHandler );
	//				
	//				u32 k=0;
	//				while( (read32( P2C(__DVDInterruptHandler) + k ) & 0xFFFF) != 0x0673 )
	//					k+=4;
	//				
	//				dbgprintf("  Patch@0x%08x\n", P2C(__DVDInterruptHandler) + k );
	//				
	//				//write32( P2C(__DVDInterruptHandler) + k + 0, read32( P2C(__DVDInterruptHandler) + k + 12 ) );	// copy "rlwinm. %r0, %r27, 0,27,27"
	//				write32( P2C(__DVDInterruptHandler) + k + 0, read32( P2C(__DVDInterruptHandler) + k + 20 ) );	// copy "ori     %r29, %r29, 1"

	//				memcpy( (void*)(P2C(__DVDInterruptHandler) + k + 4), DVDIRQWaitB, sizeof(DVDIRQWaitB) );			

	//				hexdump( (void*)(P2C(__DVDInterruptHandler) + k ), sizeof(DVDIRQWaitB) );
	//				break;
	//			}
	//		}
	//		break;
	//	}
	//}

	//Timer = (read32(HW_TIMER) - Timer) * 19 / 10;
	//dbgprintf("DVDIRQ ----> Time: %4d [ms]\n", Timer );
	//Timer = read32(HW_TIMER);

	//if( __DVDInterruptHandler == 0 )
	//{
	//	dbgprintf("Failed to find __DVDInterruptHandler!\n");
	//	while(1);
	//}


//Note: ORing the values prevents an early break out when a single patterns has multiple hits
	u32 PatchCount=0;
	
	
	//memcpy( (void*)0x00A33D8, OSReportDM, sizeof(OSReportDM) );
	//memcpy( (void*)0x00AEA14, DVDReadAbsAsyncPrio, sizeof(DVDReadAbsAsyncPrio) );

	for( i=0; i < size; i+=4 )
	{
		//if( *(u32*)(ptr + i) == AlarmHandlerForTimeout )
		//{
		//	write32( (u32)ptr + i, (__DVDInterruptHandler & 0x0000FFFF) | (read32( (u32)ptr + i) & 0xFFFF0000 ) );
		//	dbgprintf("Patch@0x%08X->0x%08X\n", ptr + i + SectionOffset, read32( (u32)ptr + i) );
		//}
		
		//if( read32( (u32)ptr + i ) == 0x3C60A800 ) 
		//{
		//	int j=0;
		//	while( read32( (u32)ptr + i - j ) != 0x7C0802A6 )
		//		j+=4;

		//	//Check if there is a lis %rX, 0xCC00 in this function
		//	//At least Sunshine has one false hit on lis r3,0xA800
		//	int k=0;
		//	while( 1 )
		//	{
		//		if( read32( (u32)ptr + i + k - j ) == 0x4E800020 )
		//			break;
		//		if( (read32( (u32)ptr + i + k - j ) & 0xF83FFFFF) == 0x3800CC00 )
		//			break;

		//		k += 4;
		//	}
		//	
		//	if( read32( (u32)ptr + i + k - j ) == 0x4E800020 )
		//		continue;
		//	
		//	dbgprintf("DVDLowRead@0x%08X\n", (u32)ptr + i - j + SectionOffset );
		//	
		//	u32 ValA = read32( (u32)ptr + i - j + 0x2C );
		//	u32 ValB = read32( (u32)ptr + i - j + 0x34 );

		//	dbgprintf("ValA:%08X ValB:%08X\n", ValA, ValB );

		//	memcpy( (void*)((u32)ptr + i - j), DVDLowReadShift, sizeof(DVDLowReadShift) );
		//	
		//	write32( (u32)ptr + i - j + 0x18, ValB );
		//	write32( (u32)ptr + i - j + 0x1C, ValA );

		//	PatchCount|=1;
		//}		

		if( read32( (u32)ptr + i + 0 ) == 0x90030020 &&
			read32( (u32)ptr + i + 4 ) == 0x90E30028
		  )
		{
			int j=0,Found=0;
			while( read32( (u32)ptr + i - j ) != 0x7C0802A6 )
			{
				if( read32( (u32)ptr + i - j ) == 0x38000001 ) // 1 is ReadAsync, 2 ReadAsyncForBS, 4 ReadDiscIDAync
					Found=1;
				j+=4;
			}

			if( Found )
			{
				dbgprintf("DVDLowRead@0x%08X\n", (u32)ptr + i - j + SectionOffset );
				memcpy( (void*)((u32)ptr + i - j), DVDReadAbsAsyncPrio, sizeof(DVDReadAbsAsyncPrio) );
				PatchCount |= 1;
			}
		}
		
#ifndef CHEATHOOK
		if( memcmp( ptr + i, __fwriteGC, sizeof(__fwriteGC) ) == 0 ||
			memcmp( ptr + i, __fwriteGCB, sizeof(__fwriteGCB) ) == 0 ) 
		{
			dbgprintf("__fwrite@0x%08X\n", i + SectionOffset );
			memcpy( ptr + i, patch_fwrite_GC, sizeof(patch_fwrite_GC) );

			PatchCount|=2;
		}
#endif
		
		if( memcmp( ptr + i, AIResetStreamSampleCount, sizeof(AIResetStreamSampleCount) ) == 0 ) 
		{
			dbgprintf("AIResetStreamSampleCount@0x%08X\n", (u32)ptr + i + SectionOffset );
			write32( (u32)ptr + i + 0x04, 0x60000000 );
			write32( (u32)ptr + i + 0x10, 0x60000000 );

			PatchCount|=4;
		}
		//if( memcmp( ptr + i, ARStartDMA, sizeof(ARStartDMA) ) == 0 ) 
		//{
		//	dbgprintf("ARStartDMA@0x%08X\n", (u32)ptr + i + SectionOffset );

		//	//Fill area with nops
		//	u32 j;
		//	for( j = 0; j < 0x9C; j+=4 )
		//		write32( (u32)ptr + i + j, 0x60000000 );

		//	memcpy( ptr + i, ARAMTransfer, sizeof(ARAMTransfer) );
		//}
		if( read32( (u32)ptr + i ) == 0x3C608000 )
		{
			if( (read32( (u32)ptr + i + 4 ) & 0xFFFF) == 0x00CC &&
				(read32( (u32)ptr + i + 16) >> 24) == 0x7C )
			{
				dbgprintf("VIPatch@0x%08x\n", (u32)ptr + i + SectionOffset );
				write32( (u32)ptr + i + 16, read32( (u32)ptr + i + 4 ) + (1<<21) );
				PatchCount|=8;
			}
		}
#ifdef CHEATHOOK
		if( read32( (u32)ptr + i + 0 ) == 0x7C800378 &&
			read32( (u32)ptr + i + 4 ) == 0x7CA31B78 )
		{
			dbgprintf("VIFlush@0x%08x", (u32)ptr + i + SectionOffset );

			//search for end of function to place our hook
			int k=0;
			while( 1 )
			{
				if( read32( (u32)ptr + i + k ) == 0x4E800020 )
					break;
				k += 4;
			}

			dbgprintf("   Hook@0x%08x\n", (u32)ptr + i + k + SectionOffset );

			memcpy( (void*)0x1800, kenobigc, sizeof(kenobigc) ); 
		
			write32( P2C(read32(0x1808)), 1 );

			u32 newval = (0x18A8 - ((u32)ptr + i + k));
			newval&= 0x03FFFFFC;
			newval|= 0x48000000;
			write32( ((u32)ptr + i + k), newval );

			PatchCount|=0x10;
		}

		if( PatchCount == 0x1D )
			break;
#else 
		if( PatchCount == 0xF )
			break;
#endif
	}


	Timer = (*(vu32*)0x0d800010 - Timer) * 19 / 10;
	dbgprintf("Patches ----> Time: %4d [ms]\n", Timer );

}